package com.aaa.service.impl;

import com.aaa.dao.UserInfoDao;
import com.aaa.entity.PageSort;
import com.aaa.entity.Userinfo;
import com.aaa.service.UserInfoService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class UserInfoServiceImpl  implements UserInfoService {
    @Autowired
    private UserInfoDao userInfoDao;
    @Override
    public Page selectAllUserInfo(PageSort pageSort) {
       Page<Userinfo> page= PageHelper.startPage(pageSort.getPage(), pageSort.getLimit());
        List<Userinfo> userinfoList = userInfoDao.selectAllUserInfo(pageSort);
        Page listPage= (Page) userinfoList;
        return  listPage;
        // return userInfoDao.selectAllUserInfo();

    }

    @Override
    public boolean deleteUserInfoById(Integer userid) {
     int i=  userInfoDao.deleteUserInfoById(userid);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteUserInfoBatch(String userid) {
        int i=userInfoDao.deleteUserInfoBatch(userid);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateUserInfo(Userinfo userinfo) {
        int i=userInfoDao.updateUserInfo(userinfo);
        if (i>0){
            return  true;
        }
        return false;
    }



    @Override
    public boolean insertUserRole(Userinfo userinfo) {
        int insertUserRole = userInfoDao.insertUserRole(userinfo);
        if (insertUserRole>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateUserRole(Userinfo userinfo) {
        int updateUserRole = userInfoDao.updateUserRole(userinfo);
        if (updateUserRole>0){
            return true;

        }
        return false;
    }

    @Override
    public boolean deleteUserRoleById(Integer userid) {
        int deleteUserRoleById = userInfoDao.deleteUserRoleById(userid);
        if (deleteUserRoleById>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteUserRoleBatch(String userid) {
        int deleteUserRoleBatch = userInfoDao.deleteUserRoleBatch(userid);
        if (deleteUserRoleBatch>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateInfo(Userinfo userinfo) {
        int i=userInfoDao.updateInfo(userinfo);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean resetPassword(Userinfo userinfo) {
        int i=userInfoDao.resetPassword(userinfo);
        if (i>0){
            return true;
        }
        return false;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean insertUserInfo(Userinfo userinfo) throws ClassNotFoundException {
        int i=userInfoDao.insertUserInfo(userinfo);
//        int t=1/0;
//        Class.forName("adfaf");
        int a=userInfoDao.addUser();
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public List<Map<String, Object>> findAllUserInfoByName(Map map) {
        return userInfoDao.findAllUserInfoByName(map);
    }

    @Override
    public boolean selectLoginByName(Userinfo userinfo) {
        List<Userinfo> userinfoList = userInfoDao.selectLoginByName(userinfo);
        if (userinfoList!=null&&userinfoList.size()>0){
            return true;
        }
        return false;
    }

//    @Override
//    public int addUser() {
//
//        return 0;
//    }
}
